package com.xinjixian.webgame;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.NonNull;

import com.bun.miitmdid.core.JLibrary;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Progress;
import com.lzy.okserver.OkDownload;
import com.mcxiaoke.packer.helper.PackerNg;
import com.xunmeng.pap.action.PAPAction;

import java.util.HashMap;
import java.util.List;

import static com.bun.miitmdid.core.JLibrary.context;

public class MyApplication extends Application {
    public static String AGENT_ID;
    //街机捕鱼  8  天行道 	7  小小勇士 6 	少年封神 5
    public static String GAMEID = "5";
    public static String OAID = "";
    private static MyApplication myApplication;

    public static MyApplication getApplication() {
        return myApplication;
    }

    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();
        myApplication = this;

        String channel = PackerNg.getChannel(this);
        Log.i("Application", "channel=" + channel);
        if (TextUtils.isEmpty(channel)) {
            AGENT_ID = "1";
        } else {
            AGENT_ID = channel;
        }
        try {
           //PAPAction.init(this, "14181", "519516dd6287db4e38c45bb17f7c73c9aa4bce8a", true);
        } catch (Exception e) {//PAPTrans
            e.printStackTrace();
        }
        //初始化下载模块
        OkGo.getInstance().init(this);
        OkDownload.getInstance().setFolder(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Download/");
        OkDownload.getInstance().getThreadPool().setCorePoolSize(1);
        List<Progress> progressList = com.lzy.okgo.db.DownloadManager.getInstance().getAll();
        OkDownload.restore(progressList);

    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        JLibrary.InitEntry(base);//移动安全联盟配置
        new JFQMiitHelper(new JFQMiitHelper.AppidsUpdater() {
            @Override
            public void OnIdsAvalid(@NonNull String oaid) {
                //存入oaid
                if (!TextUtils.isEmpty(oaid)) {
                    OAID = oaid;
                    SharedPreferences jfqoaid = context.getSharedPreferences("jfqoaid", Context.MODE_PRIVATE);
                    jfqoaid.edit().putString("oaid", oaid).commit();
                }

            }
        }).getDeviceIds(context);
    }
}
